<template>
    <div class="con">
        <div class="nav">
            <span v-for="(item, index) in navList" @click="altNav(index)" :key="item.value" :class="index == activity ? 'activity' : ''"> {{ item.value }}</span>
        </div>
        <div class="search">
            <div class="origin"><img src="../../assets/img/bd.png" alt="" /></div>
            <input type="text" placeholder="输入并搜索" v-model="search" @keydown.enter="start" />
            <div class="icon"><img src="../../assets/img/search.png" alt="" @click="start" /></div>
        </div>
        <a href="#" id="a"></a>
    </div>
</template>

<script>
export default {
    data() {
        return {
            search: '',
            activity: 0,
            navList: [
                {
                    value: '网页',
                    url: 'https://www.baidu.com/s?tn=02003390_42_hao_pg&ie=utf-8&wd=',
                },
                {
                    value: '照片',
                    url: 'https://image.baidu.com/search/index?tn=baiduimage&ie=utf-8&word=',
                },
                {
                    value: '视频',
                    url: 'http://video.baidu.com/v?ie=utf-8&word=',
                },
                {
                    value: '地图',
                    url: 'http://map.baidu.com/?newmap=1&ie=utf-8&s=s%26wd%3D',
                },
                {
                    value: '翻译',
                    url: 'https://fanyi.baidu.com/?aldtype=85#en/zh/',
                },
            ],
        }
    },
    methods: {
        start() {
            const a = document.getElementById('a')
            a.href = this.navList[this.activity].url + this.search
            a.click()
        },
        altNav(i) {
            this.activity = i
        },
    },
}
</script>

<style lang="less" scoped>
.con {
    color: #fff;
    .nav {
        span {
            margin: 10px;
            font-size: 22px;
            line-height: 2;
            cursor: pointer;
            color: #eee;
            user-select: none;
        }
        .activity {
            color: #fff;
            font-size: 24px;
        }
    }

    .search {
        display: flex;
        width: 720px;
        height: 60px;
        padding: 0 10px;
        border-radius: 8px;
        background: #fff;
        justify-content: space-between;
        align-items: center;

        .origin {
            width: 60px;
            text-align: center;
            margin-right: 10px;
            img {
                width: 35px;
            }
        }

        .icon {
            width: 60px;
            text-align: center;
            cursor: pointer;

            img {
                width: 30px;
            }
        }

        input {
            flex: 1;
            height: 60px;
            font-size: 22px;
        }
    }
}
</style>
